-- Created		06/02/2009
-- Modified	
-- Author		wilfried.vandenberghe@gmail.com
-- Version		1.0
-- Database	Oracle 10g 

-- COMPOSITE type definition
-- Define a content that is a composition of CONTENT.
CREATE TYPE COMPOSITECONTENT UNDER CONTENT 
(	
	-- List of content
	content_list CONTENTLIST,
	
	-- 
	-- Constructor without parameters
	-- 
	CONSTRUCTOR FUNCTION COMPOSITECONTENT RETURN SELF AS RESULT,
	
	--
	-- Overriding method from CONTENT
	--
	OVERRIDING MEMBER FUNCTION format RETURN LONG,
	
	--
	-- Add a content
	--
	MEMBER PROCEDURE add_content(c CONTENT)
);
/

CREATE TYPE BODY COMPOSITECONTENT AS

	CONSTRUCTOR FUNCTION COMPOSITECONTENT RETURN SELF AS RESULT AS
	BEGIN
		RETURN;
	END COMPOSITECONTENT;

	OVERRIDING MEMBER FUNCTION format RETURN LONG IS
		res LONG;
		c INTEGER;
	BEGIN
		FOR c IN SELF.content_list.FIRST .. SELF.content_list.LAST
		LOOP
			res := res || SELF.content_list(c).format;
		END LOOP;
		
		RETURN res;
	END format;
	
	MEMBER PROCEDURE add_content(c CONTENT) IS
	BEGIN
		IF content_list IS NULL THEN
			SELF.content_list := CONTENTLIST(c);
		ELSE
			SELF.content_list.extend();
			SELF.content_list(SELF.content_list.count()) := c;
		END IF;
	END add_content;

END;
/
